package cn.weixindong.controller;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alipay.api.AlipayClient;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.weixindong.pojo.AccountAdjust;
import cn.weixindong.pojo.AccountAdjustExample;
import cn.weixindong.pojo.AccountAdjustExample.Criteria;
import cn.weixindong.service.AccountAdjustService;
import cn.weixindong.utils.JsonUtils;

@RestController
public class AController {

	
	
	@Autowired
	private AccountAdjustService accountAdjustService;

	@Autowired
	private AlipayClient client;

	@Autowired
	private StringRedisTemplate stringRedisTemplate;

	// 分页查询

	@RequestMapping(value = "c", method = RequestMethod.GET)
	public PageInfo<AccountAdjust> home1() throws Exception {
		System.out.println("执行c");
		
		
		// 删除键
		stringRedisTemplate.delete("zzfp");
		stringRedisTemplate.opsForValue().set("qdf", "bigz");
		// 设置hashkey
		stringRedisTemplate.opsForHash().put("fdsf", "fdsf", "fdsfsfl");

		// 设置过期时间
		stringRedisTemplate.opsForValue().set("qdf", "100", 1900, TimeUnit.SECONDS);

		PageHelper.startPage(6, 2);

		AccountAdjustExample example = new AccountAdjustExample();

		Criteria andManagerIdEqualTo = example.createCriteria().andManagerIdEqualTo(28);
		List<AccountAdjust> query = accountAdjustService.query(example);
		stringRedisTemplate.opsForValue().set("list", JsonUtils.objectToJson(query));
		PageInfo<AccountAdjust> pageInfo = new PageInfo<>(query);

		String string = stringRedisTemplate.opsForValue().get("list");

		List<AccountAdjust> jsonToList = JsonUtils.jsonToList(string, AccountAdjust.class);
		System.out.println(jsonToList.get(0).toString());

		return pageInfo;

	}

	@Cacheable(value = "peopl")
	@RequestMapping(value = "bb", method = RequestMethod.GET)
	public String home12() throws Exception {
		System.out.println("执行bb");

		AccountAdjustExample example = new AccountAdjustExample();

		Criteria andManagerIdEqualTo = example.createCriteria().andManagerIdEqualTo(28);
		List<AccountAdjust> querys = accountAdjustService.query(example);

		return querys.toString();

	}}

	